//给一个有工资收入和稿费收入的小伙伴算税。
public class Saray {
    
    public static void main(String[] args){
     
        //Income引用类型数组
        Income[] s = {
            new Pub(2000),
            new Salary(6000),
        };

        // Income[] s = new Income[] { new Pub(8000), new Salary(12000) };
        
        getTotalTax(s);

    }

    //计算所有的税
    public static void getTotalTax(Income... incomes) { // Income... 可变参数
            
        //total tax
        double total = 0;
        for(Income i : incomes){
            // System.out.println(i.getTax());
            total += i.getTax();
        }

        System.out.println(total);
    }
}


//base class
class Income {
    protected  double income;

    //构造方法
    public Income(double income){
        this.income = income;
    }


    public double getTax(){
        return income * 0.1; // 税率10%
    }

}



class Pub extends Income{

    //构造方法
    public Pub(double income){
        //执行父类的构造方法
        super(income);
    }


    //(覆写)重写父类的方法
    @Override
    public double getTax(){
        if(income >=1000){
            return income * 0.2;
        }else{
            return income * 0.1;
        }
    }

}



class Salary extends Income {

    public Salary(double income){
        super(income);
    }

    @Override
    public double getTax(){
        if(income >= 5000 ){
            return (income - 5000) * 0.3;
        }else{
            return income * 0.1;
        }
    }
}


